from flask_wtf import FlaskForm
from wtforms import StringField, PasswordField, SelectField, SubmitField
from wtforms.validators import DataRequired, Email, Length, EqualTo
# 基于flask_wtf处理用户登录注册的字段验证

# 登录表单类
class LoginForm(FlaskForm):
    username = StringField('工号/学号', validators=[DataRequired()])
    password = PasswordField('密码', validators=[DataRequired()])
    submit = SubmitField('登录')

    class Meta:
        csrf = True  # 启用CSRF跨站请求保护

# 注册表单类
class RegistrationForm(FlaskForm):
    user_type = SelectField('身份', choices=[('teacher', '教师'), ('student', '学生')], validators=[DataRequired()])
    user_id = StringField('工号/学号', validators=[DataRequired()])
    username = StringField('用户名', validators=[DataRequired(), Length(min=2, max=5, message='用户名长度必须在2-5个字符之间')])
    password = PasswordField('密码', validators=[DataRequired(), Length(min=6, message='密码长度不能少于6个字符')])
    confirm_password = PasswordField('确认密码', validators=[DataRequired(), EqualTo('password', message='两次输入的密码不一致')])
    email = StringField('邮箱', validators=[DataRequired(), Email(message='请输入有效的邮箱地址')])
    phone = StringField('手机号', validators=[DataRequired(), Length(min=11, max=11, message='请输入11位手机号')])
    submit = SubmitField('注册') 